/********************************************
 * 功能说明: 
 * 模块名称: 
 * 系统名称: 
 * 软件版权: Frank
 * 系统版本: 1.0.0
 * 开发人员: Frank
 * 开发时间: 2019/12/9 10:55
 * 审核人员: 
 * 相关文档: 
 * 修改记录: 修改日期 修改人员 修改说明
 *********************************************/
package com.spring.arch.uaa.model;

import com.spring.arch.common.jpa.model.AbstractLogicalModel;
import com.spring.arch.common.validator.constraints.Mobile;
import com.spring.arch.uaa.enums.TenantStatus;
import com.spring.arch.common.jpa.model.AbstractLogicalModel;
import com.spring.arch.common.validator.constraints.Mobile;
import com.spring.arch.uaa.enums.TenantStatus;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * 租户信息
 *
 * @author Frank
 * @version 1.0.0.1
 * @since 2019/12/9 10:55
 */
@NoArgsConstructor
@Getter
@Setter
@Entity
@Table(name = "tenant")
public class Tenant extends AbstractLogicalModel {

    private static final long serialVersionUID = -303223029734783742L;

    /**
     * 租户编码，系统生成
     */
    @NotBlank
    @Size(max = 32)
    @Column(nullable = false, unique = true)
    private String code;

    /**
     * 租户名称
     */
    @NotBlank
    @Size(max = 64)
    @Column(nullable = false, unique = true)
    private String name;

    /**
     * 租户简称
     */
    @NotBlank
    @Size(max = 32)
    @Column(nullable = false, unique = true)
    private String abbreviation;

    /**
     * 租户根组织
     */
    @OneToOne(fetch = FetchType.LAZY)
    private Organization rootOrganization;

    /**
     * 联系人
     */
    @NotBlank
    @Size(max = 64)
    @Column(nullable = false)
    private String contact;

    /**
     * 联系电话
     */
    @NotBlank
    @Size(max = 11)
    @Mobile
    @Column(nullable = false)
    private String mobile;

    /**
     * 租户状态
     */
    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(length = 32)
    private TenantStatus status;

    /**
     * 域名，租户的独立域名，需要完成映射
     */
    @Size(max = 255)
    private String domain;

    /**
     * 子域名，系统自动提供的子域名前缀
     */
    @Size(max = 64)
    private String domainIdentity;

    /**
     * 租户Logo的图片
     */
    @Size(max = 128)
    private String logo;

    public Tenant(@NotBlank @Size(max = 32) String code,
                  @NotBlank @Size(max = 32) String abbreviation,
                  @NotBlank @Size(max = 64) String name,
                  @NotBlank @Size(max = 64) String contact,
                  @NotBlank @Size(max = 11) String mobile,
                  @NotNull TenantStatus status,
                  @Size(max = 255) String domain,
                  @NotBlank @Size(max = 64) String domainIdentity,
                  @Size(max = 128) String logo) {
        this.code = code;
        this.name = name;
        this.abbreviation = abbreviation;
        this.contact = contact;
        this.mobile = mobile;
        this.status = status;
        this.domain = domain;
        this.domainIdentity = domainIdentity;
        this.logo = logo;
    }
}
